using System.Data;
using Fadd.Data.Mappings;

namespace Fadd.Data
{
    /// <summary>
    /// Used 
    /// </summary>
    public interface IConnectionHelper
    {
        /// <summary>
        /// Connection string
        /// </summary>
        string ConnectionString{ get;}

        /// <summary>
        /// Create a new connection to the database.
        /// </summary>
        /// <returns>An open database connection.</returns>
        /// <exception cref="DataLayerException">If connection fails.</exception>
        IDbConnection CreateConnection();

        /// <summary>
        /// Try to get next sequence value.
        /// </summary>
		/// <param name="command">A command to perform actions with, we pass commands since they might be in a transaction.</param>
        /// <param name="sequenceName">Name of the sequence/generator.</param>
        /// <returns>A generated value.</returns>
        /// <exception cref="DataLayerException">If something failed </exception>
		object GetNextSequenceValue(IDbCommand command, string sequenceName);

        /// <summary>
        /// Gets the latest auto incremented value from the database.
        /// </summary>
		/// <param name="command">A command to perform actions with, we pass commands since they might be in a transaction..</param>
        /// <param name="columnName">Name of the column that the auto incremented value is for.</param>
        /// <returns>auto incremented value</returns>
        /// <exception cref="DataLayerException">If something failed </exception>
		object GetAutoIncrementValue(IDbCommand command, string columnName);

        /// <summary>
        /// Modifies the SQL statement to include paging.
        /// </summary>
        /// <param name="mapping">Database mapping</param>
        /// <param name="sqlStatement">SQL statement generated by the DAL.</param>
        /// <param name="page">0 based index</param>
        /// <param name="pageSize">number of entries per page</param>
        /// <returns>SQL statement with paging</returns>
        /// <example>
        /// <code>
        /// helper.Paging("SELECT * FROM users", 5, 10); // --> "SELECT * FROM users LIMIT 10 OFFSET 50"
        /// </code>
        /// </example>
        string Paging(IMapping mapping, string sqlStatement, int page, int pageSize);
    }
}
